package com.mashibing.practice01.conf;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

/**
 * @author liuyno
 * @date 2021/3/11 - 23:55
 */
public class ZKUtils {

    private static ZooKeeper zk;
    private static String url ="192.168.1.10:2181,192.168.1.40:2181,192.168.1.30:2181";
    private static DefaultWatch watch = new DefaultWatch();
    private static CountDownLatch cd = new CountDownLatch(1);

    public static ZooKeeper getZk(){
        try {
            zk = new ZooKeeper(url, 3000, watch);
            watch.setCd(cd);
            cd.await();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return zk;
    }



}
